
<div id="sidebar">
    <div id="">
        <h2><?php __('Actions'); ?></h2>

        <?php if($type == 'host'){ ?>
           <div class="actions">
                <ul>
                        <li><?php echo $this->Html->link(__('Edit Event', true), array('action' => 'edit', $event['Event']['id'])); ?> </li>
                        <li><?php echo $this->Html->link(__('Delete Event', true), array('action' => 'delete', $event['Event']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $event['Event']['id'])); ?> </li>

                        <li><?php echo $this->Html->link(__('Back', true), array('action' => 'index')); ?> </li>


                </ul>
            </div>
        <br />
         <div class="actions">
             <div class="related">
                 <h2><?php __('Related Event Hosts'); ?></h2>
                 <?php if (!empty($temp)): ?>
                     <table cellpadding = "0" cellspacing = "0">
                         <tr>
                             <th><?php __('Id'); ?></th>
                             <th><?php __('Business Name'); ?></th>
                             <th><?php __('Host Type'); ?></th>
                             <th><?php __('Action'); ?></th>
                            
                             </tr>
                     <?php
                     $i = 0;
                     foreach ($temp as $eventHost):
                         $class = null;
                         if ($i++ % 2 == 0) {
                             $class = ' class="altrow"';
                         }
                     ?>
                         <tr<?php echo $class; ?>>
                             <td><?php echo $eventHost['EventHost']['id']; ?></td>
                             <td><?php 
                             
                             $EHI= $eventHost['Host']['business_name'];
                             echo $EHI;
                           //  $user_id = $user['id'];
                             //echo $user_id;
                             
                            // $biz = findName($EHI);
                            // $bus= implode(' ',$biz);
                             
                           // echo $biz; ?>
                            </td>
                             <td>   <?php    if($eventHost['EventHost']['host_type']=='p')
                             {
                                 echo 'Primary';


                             }
                             else if ($eventHost['EventHost']['host_type'] == 's')
                             {

                                 echo 'Secondary';

                             }




                                 ?></td>
                             
                                
                                  <?php
                                  echo '<td class="actions">';
                                  if($eventHost['EventHost']['host_type'] == 's'){
                                      
                                      echo $this->Html->link(__('Remove', true), array('controller'=>'event_hosts', 'action' => 'delete', $eventHost['EventHost']['id']), null, sprintf(__('Are you sure you want to delete  %s?', true), $eventHost['EventHost']['id']));
                                     
                                  }
                                   echo '</td>';
                                  ?>
                                       
                           
                             
                     </tr>
<?php endforeach; ?>
                 </table>
<?php endif; ?>
        
                         <div class="actions">
                             <ul>
                                 <li><?php echo $this->Html->link(__('Assign new co-host', true), array('controller' => 'event_hosts', 'action' => 'add', $event['Event']['id'])); ?> </li>
                                 </ul>
                             </div>
                         </div>
        </div>

        <?php }else{ ?>

            <div class="actions">
                <ul>
                    <li><?php echo $this->Html->link(__('Local events', true), array('controller' => 'events', 'action' => 'index','local_events')); ?> </li>

                    <li><?php echo $this->Html->link(__('My RSVPs', true), array('controller' => 'events', 'action' => 'index','rsvps')); ?> </li>

                    <li><?php echo $this->Html->link(__('My invites', true), array('controller' => 'events', 'action' => 'index','invites')); ?> </li>

                    <li><?php echo $this->Html->link(__('Edit my profile', true), array('controller' => 'users', 'action' => 'edit_profile',$id_user)); ?></li>
                </ul>
            </div>

        <?php } ?>
    </div>
</div>

<div class="events view">
<h2><?php echo $event['Event']['event_name']; ?></h2>

<?php if($type == 'user'){

            $date = date('Y-m-d H:i:s');

            if (($date > $event['Event']['rsvp_start']) && ($date < $event['Event']['rsvp_end'])){
?>

    <h3>Your RSVP information</h3>
    <div class="event_listing">

        <div class="event_listing_detail2">
            <p><span class="small_title">First name: </span><?php echo $first_name; ?></p>
            <p><span class="small_title">Last name: </span><?php echo $last_name; ?></p>
        </div>
               
        <?php

            if ($date < $event['Event']['event_start']){

                echo $form->create(null, array('url' => array('controller' => 'rsvps', 'action' => 'rsvp_action',$id_event,$ev_type)));

                $options=array('Y'=>'I\'m attending','M'=>'Maybe','N'=>'No');
                $attributes=array('legend'=>false,'value'=>$attendance);
                echo $form->radio('attending',$options,$attributes);

                echo '<br/>';

                $options=array('0'=>'0','1'=>'1','2'=>'2','3'=>'3','4'=>'4');
                $attributes=array('empty'=>false);
                echo $form->label('Number of guests ');
                echo $form->select('n_guests',$options,$n_guests,$attributes);

                echo $form->end('Submit');
                
            }
            else{

                echo '<div class="event_listing_detail2">';

                if (isset($attendance)){

                    if ($attendance == 'N'){
                        echo '<span class="small_title">You did not attend this event.</span>';
                    }else{
                        if ($n_guests > 0){
                            echo '<span class="small_title">You and '.$n_guests.' more guest(s) attended this event.</span>';
                        }else{
                            echo '<span class="small_title">You attended this event.</span>';
                        }
                    }

                }else{
                    echo '<span class="small_title">You did not attend this event.</span>';
                }

                echo '</div>';

            }
        ?>

    </div>

    <?php } ?>

<?php } ?>


    <h3>Details</h3>

    <div class="event_listing">
        <div class="event_listing_left">
            <?php
                if(file_exists('img/event/'.$event['Event']['id'].'.jpg')){
                    echo $this->Html->image('event/'.$event['Event']['id'].'.jpg',array('height'=>'90','width'=>'90'));
                }else{
                    echo $this->Html->image('default_event.jpg',array('height'=>'90','width'=>'90'));
                }
            ?>
        </div>
        <div class="event_listing_right">
            <p><span class="small_title">Location: </span><?php echo $event['Event']['venue_addr1'].', '. $event['Event']['venue_city'].', '. $event['Event']['venue_state'].' '. $event['Event']['venue_postal']; ?></p>
            <p><span class="small_title">Start Time: </span><?php echo $event['Event']['event_start']; ?></p>
            <p><span class="small_title">End Time: </span><?php echo $event['Event']['event_end']; ?></p>
            <p><span class="small_title">Event Type: </span><?php echo $event['Event']['event_type']; ?></p>
            <p><span class="small_title">Attending: </span><?php echo $attending; ?></p>
            <p><span class="small_title">Remaining capacity: </span><?php echo $remaining_capacity.'/'.$event['Event']['capacity']; ?></p>
            <p><span class="small_title">Details: </span><?php echo $event['Event']['description']; ?></p>
            <p><span class="small_title">RSVP Start Time: </span><?php echo $event['Event']['rsvp_start']; ?></p>
            <p><span class="small_title">RSVP End Time: </span><?php echo $event['Event']['rsvp_end']; ?></p>
        </div>
        
        <div class="event_listing_detail"></div>
        <div id="event_listing_clear"></div>
    </div>


    <?php

    if(($type=='user')&&($date > $event['Event']['event_start']) && ($ev_type == 'rsvps') && ($attendance != 'N')){ //You can only make reviews for your past rsvp events

    ?>

    <h3>Update your review</h3>
    <div class="event_listing">

        <?php
            if (isset($user_review)){
                echo $form->create(null, array('url' => array('controller' => 'reviews', 'action' => 'review_action',$id_event,$rsvp_id,$review_id)));
            }else{
                echo $form->create(null, array('url' => array('controller' => 'reviews', 'action' => 'review_action',$id_event,$rsvp_id)));
            }

            
        ?>

        <?php

            if (isset($user_review)){
                echo $form->textarea('comment',array('value'=>$user_review));
            }else{
                echo $form->textarea('comment');
            }


            echo '<br/><br/>';

            $options=array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5');
            $attributes=array('empty'=>false);
            echo $form->label('Rating: ');

            if (isset($user_rating)){
                echo $form->select('rating',$options,$user_rating,$attributes);
            }else{
                echo $form->select('rating',$options,1,$attributes);
            }

            echo '<br/><br/>';

            if (isset($review_date)){
                echo $form->label('Reviewed at: '.$review_date);
            }
            
        ?>

        <?php

            echo $form->end('Update');
        ?>

    </div>

    <h3>Guest reviews</h3>
    <div class="event_listing">

        <?php

            if (!empty($reviews_list)){

                $j = 0;
                foreach ($reviews_list as $review):

       ?>

        <div class="event_listing_left">
            <?php
                if(file_exists('img/profile/user/'.$users_list[$j]['User']['id'].'.jpg')){
                    echo $this->Html->image('profile/user/'.$users_list[$j]['User']['id'].'.jpg',array('height'=>'90','width'=>'90'));
                }else{
                    echo $this->Html->image('default_user.jpg',array('height'=>'90','width'=>'90'));
                }
            ?>
        </div>

        <div class="event_listing_right">
            <h4><?php echo $users_list[$j]['User']['first_name'].' '.$users_list[$j]['User']['last_name']; ?></h4>
            <p><span class="small_title">Comment: </span><?php echo $review['Review']['comment']; ?></p>
            <p><span class="small_title">Rating: </span><?php for($i=0 ; $i<$review['Review']['rating']; $i++) echo '*'; ?></p>
            <p><span class="small_title">Reviewed at: </span><?php echo $review['Review']['review_ts']; ?></p>
        </div>

        <div class="event_listing_detail"></div>
        <div id="event_listing_clear"></div>

        <?php $j++; endforeach;

            }else{?>

        <div class="event_listing_detail2">
            <p><span class="small_title">There are no reviews available.</span></p>
        </div>

        <?php } ?>

    </div>


    <?php } ?>
	
</div>

<?php

//function findName($EHI)

//{

    //find('list', array('fields'=>array('Host.business_name')
  //                            ,'conditions'=>array('id'=>$EHI)));



//}

?>